package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.PlayLocalActivity;
import flc.ast.activity.PlayRecordActivity;
import flc.ast.activity.PlayUriActivity;
import flc.ast.activity.SelVideoActivity;
import flc.ast.adapter.PlayRecordAdapter;
import flc.ast.bean.RecordBean;
import flc.ast.databinding.FragmentPlayBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link PlayFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class PlayFragment extends BaseNoModelFragment<FragmentPlayBinding> {

    private List<RecordBean> listShow=new ArrayList<>();
    private PlayRecordAdapter recordAdapter;

    @Override
    protected int onCreate() {
        return R.layout.fragment_play;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        mDataBinding.ivPlayFormat.setOnClickListener(this);
        mDataBinding.ivPlayUri.setOnClickListener(this);
        mDataBinding.ivPlayLocal.setOnClickListener(this);
        mDataBinding.tvRecordMore.setOnClickListener(this);
        mDataBinding.rvRecordList.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
        recordAdapter=new PlayRecordAdapter();
        mDataBinding.rvRecordList.setAdapter(recordAdapter);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivPlayFormat://格式播放
                startActivity(SelVideoActivity.class);
                break;
            case R.id.ivPlayUri://链接播放
                startActivity(PlayUriActivity.class);
                break;
            case R.id.ivPlayLocal://本地播放
                startActivity(PlayLocalActivity.class);
                break;
            case R.id.tvRecordMore://播放记录
                startActivity(PlayRecordActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        getData();
    }

    private void getData(){
        listShow.clear();
        List<RecordBean> listSp = AppSpUtils.getPlayRecordList();
        if (listSp != null && listSp.size() > 0) {
            if(listSp.size()>3){
                listShow=listSp.subList(0, 3);
            }else{
                listShow.addAll(listSp);
            }
            recordAdapter.setList(listShow);
            mDataBinding.rvRecordList.setVisibility(View.VISIBLE);
            mDataBinding.ivRecordNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvRecordList.setVisibility(View.GONE);
            mDataBinding.ivRecordNoData.setVisibility(View.VISIBLE);
        }
    }
}